<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2021/1/13
 * Time: 15:12
 */

namespace app\api\controller;


use think\Db;

class Banner extends Base
{
    private $create_time;
    
    /**
     * 异地登录验证
     * @return string
     */
    public function __construct()
    {
        $this->user_id = input('user_id');
        $this->page = input('page') ? input('page') : 1;
        $this->create_time = date('Y-m-d H:i:s');
        $time = input('time');
        $value = input('value');
        $reqKey = input('reqKey');
        $auth = $this->checkAll($this->user_id, $time, $value, $reqKey);
        if($auth == 112){
            echo json_encode(['status' => 301, 'msg' => $this->otherLogin]);
            exit;
        }elseif($auth == 110){
            echo json_encode(['status' => 302, 'msg' => $this->frost]);
            exit;
        }elseif($auth == 2111){
            echo json_encode(['status' => 303, 'msg' => $this->del]);
            exit;
        }
    }
    
    /**
     * 轮播图
     * @return \think\response\Json
     */
    public function bannerList(){
        $banner = Db::table('up_banner')
            ->where('banner_status', 1)
            ->field('banner_id, banner_image, banner_type, banner_goods_id, banner_content, banner_link')
            ->order('banner_sort desc')
            ->select();
        if($banner){
            return json(['status' => 200, 'msg' => $banner]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }

    /**
     * 判断是否有新数据
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function haveNewAdvertising(){
        $have = Db::table('up_bo_giftbag_integral')->where('bgi_is_new', 1)->find();
        if($have){
            return json(['status' => 1, 'msg' => '']);
        }else{
            return json(['status' => 2, 'msg' => '']);
        }
    }

    /**
     * 礼包服务费获取记录，取最新100条
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function advertising(){
        $have = Db::table('up_bo_giftbag_integral')
            ->join('up_u_user', 'bgi_user_id = user_id', 'LEFT')
            ->where('bgi_type', 1)
            ->field('user_phone, bgi_price, bgi_id')
            ->order('bgi_time desc')
            ->limit(100)
            ->select();
        Db::table('up_bo_giftbag_integral')
            ->where('bgi_is_new', 1)
            ->where('bgi_type', 1)
            ->update(['bgi_is_new' => 2]);
        if($have){
            return json(['status' => 200, 'msg' => $have]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
}